﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using com.fukefu.sql;

namespace com.fukefu.tools
{
    public class SinaArticle
    {
        List<string> list = new List<string>();
        Random random = new Random();

        public SinaArticle()
        {
            SqlServerOperate sql = new SqlServerOperate();
            list = new List<string>();
            SqlDataReader re = sql.Query("select * from [全局设置].[dbo].[_sina_片段]");
            while (re.Read())
            {
                list.Add(re["cont"].ToString());
            }
            re.Close();
            sql.Close();
        }
        public string Get(List<string> link)
        {
            string result = "", line = "";
            for (int i = 0; i < link.Count - 1; i += 2)
            {
                line = list[random.Next(list.Count)];
                int a = random.Next(line.Length);
                int b = random.Next(line.Length);
                line = line.Insert(Math.Max(a, b), link[i]).Insert(Math.Min(a, b), link[i + 1]);
                result += "<p>　　" + line + "</p>";
            }
            return result;
        }
    }
}
